package com.glb.app.tools;


import com.glb.app.entity.Appointment;
import com.glb.app.service.AppointmentService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppointmentTools {


    @Autowired
    private AppointmentService appointmentService;


    @Tool(name = "预约挂号", value = "根据参数，查询工具方法queryDepartment是否可以预约，" +
            "并直接给用户回答是否可以约，并让客户确认所有预约信息，用户确认预约后进行预约,如果用户没有提供具体的医生信息，请从向量存储中找一名医生")
    public String bookAppointment(Appointment appointment) {
        Appointment one = appointmentService.getOne(appointment);
        if (one == null) {
            appointment.setId(null);
            if (appointmentService.save(appointment)) {
                return "预约成功";
            }else {
                return "预约失败";
            }
        }
        return "您已经预约过了，请核对预约时间和科室";
    }

    @Tool(name = "取消预约挂号", value = "根据参数查询预约是否存在，如果存在则删除预约信息并返回取消预约成功 , 否则返回取消预约失败")
    public String cancelAppointment(Appointment appointment) {
        Appointment one = appointmentService.getOne(appointment);
        if (one == null) {
            appointment.setId(null);
            if (appointmentService.removeById(appointment.getId())) {
                return "取消预约成功";
            }else {
                return "取消预约失败";
            }
        }
        return "您没有预约记录，请核对预约时间和科室";
    }



    @Tool(name = "查询是否有号源", value = "根据科室名称，日期时间查询医生是否有号源，并返回给用户")
    public String queryDepartment(@P(value = "科室名称")String department,
                                  @P(value = "日期") String date,
                                  @P(value = "时间,可选值：上午，下午")String time,
                                  @P(value = "医生名称",required = false)String doctor) {

        System.out.println("查询科室：" + department + "，日期：" + date + "，时间：" + time + "，医生：" + doctor);

        return "查询成功";

    }

}
